package com.changgou.search.controller;

import com.changgou.entity.Result;
import com.changgou.entity.StatusCode;
import com.changgou.search.service.ESManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author kfzhao
 * @version 1.0
 * @className ESManagerController
 * @description
 * @date 2021/12/27 15:26
 */
@RestController
@RequestMapping("/manager")
public class ESManagerController {

    @Autowired
    private ESManagerService esManagerService;

    /**
     * 创建索引库结构
     *
     * @param
     * @return com.changgou.entity.Result
     * @throws
     * @description
     * @author kfzhao
     * @date 2021/12/27 15:27
     */
    @GetMapping("/create")
    public Result create() {
        esManagerService.createMappingAndIndex();
        return new Result(true, StatusCode.OK, "创建索引库结构成功");
    }

    /**
     * 导入全部数据进es
     *
     * @param
     * @return com.changgou.entity.Result
     * @throws
     * @description
     * @author kfzhao
     * @date 2021/12/27 15:28
     */
    @GetMapping("/importAll")
    public Result importAll() {
        esManagerService.importAll();
        return new Result(true, StatusCode.OK, "导入全部数据成功");
    }

}
